================================================================================
WHATSAPP SELF-HOSTED GATEWAY - INSTALLATION CHECKLIST
================================================================================

Gunakan checklist ini untuk memastikan instalasi berjalan dengan benar.

================================================================================
PRE-INSTALLATION CHECKLIST
================================================================================

[ ] Server/Komputer sudah running
[ ] MikhMon sudah terinstall dan berjalan
[ ] PHP 7.4+ sudah terinstall
[ ] MySQL/MariaDB sudah terinstall
[ ] Internet connection stabil
[ ] HP Android/iOS dengan WhatsApp terinstall

================================================================================
INSTALLATION CHECKLIST
================================================================================

STEP 1: INSTALL NODE.JS
[ ] Download Node.js dari https://nodejs.org/
[ ] Install versi LTS (Long Term Support)
[ ] Restart terminal/command prompt
[ ] Verify: node --version (harus muncul versi)
[ ] Verify: npm --version (harus muncul versi)

STEP 2: INSTALL GATEWAY DEPENDENCIES
[ ] Buka terminal/command prompt
[ ] Masuk ke folder: cd mikhmon/whatsapp-gateway
[ ] Windows: Jalankan install.bat
[ ] Linux: Jalankan chmod +x install.sh && ./install.sh
[ ] Tunggu sampai selesai (2-5 menit)
[ ] Verify: folder node_modules sudah ada
[ ] Verify: file .env sudah ada

STEP 3: KONFIGURASI API KEY
[ ] Buka file: whatsapp-gateway/.env
[ ] Copy API_KEY yang ada (contoh: abc123def456...)
[ ] Buka file: include/whatsapp_config.php
[ ] Cari baris: define('SELFHOSTED_API_KEY', '...');
[ ] Paste API_KEY yang sama
[ ] Save file
[ ] Verify: API key sama di kedua file

STEP 4: KONFIGURASI GATEWAY
[ ] Buka file: whatsapp-gateway/.env
[ ] Cek PORT (default: 3000)
[ ] Cek DB_HOST (default: localhost)
[ ] Cek DB_USER (default: root)
[ ] Cek DB_PASS (default: kosong)
[ ] Cek DB_NAME (default: mikhmon_agents)
[ ] Sesuaikan jika perlu
[ ] Save file

STEP 5: KONFIGURASI MIKHMON
[ ] Buka file: include/whatsapp_config.php
[ ] Cek: define('WHATSAPP_GATEWAY', 'selfhosted');
[ ] Cek: define('SELFHOSTED_API_URL', 'http://localhost:3000/api/send');
[ ] Cek: define('SELFHOSTED_API_KEY', '...');
[ ] Cek: define('WHATSAPP_ENABLED', true);
[ ] Save file

STEP 6: START GATEWAY
[ ] Buka terminal/command prompt
[ ] Masuk ke folder: cd mikhmon/whatsapp-gateway
[ ] Jalankan: npm start
[ ] Tunggu sampai muncul: "Server running on http://0.0.0.0:3000"
[ ] Tunggu sampai muncul: "WhatsApp client initialized"
[ ] Jangan close terminal (biarkan running)

STEP 7: SCAN QR CODE
[ ] Buka browser
[ ] Login ke MikhMon
[ ] Pilih session
[ ] Klik menu: Settings → WhatsApp Gateway
[ ] Tunggu QR code muncul (10-30 detik)
[ ] Buka WhatsApp di HP
[ ] Tap Menu (⋮) → Linked Devices
[ ] Tap "Link a Device"
[ ] Scan QR code yang muncul di browser
[ ] Tunggu sampai status berubah "Connected"
[ ] Verify: Nomor WhatsApp muncul

STEP 8: TEST KIRIM PESAN
[ ] Di admin panel, scroll ke "Test Message"
[ ] Input nomor WhatsApp Anda: 08xxx atau 62xxx
[ ] Input pesan: "Test dari MikhMon"
[ ] Klik "Send Test Message"
[ ] Cek WhatsApp di HP
[ ] Verify: Pesan masuk

STEP 9: TEST GENERATE VOUCHER
[ ] Buka: Hotspot → Generate Users
[ ] Pilih profile (contoh: 1JAM)
[ ] Jumlah: 1
[ ] Centang "Kirim ke WhatsApp"
[ ] Input nomor WhatsApp: 08xxx
[ ] Klik Generate
[ ] Cek WhatsApp di HP
[ ] Verify: Voucher masuk

STEP 10: PRODUCTION SETUP (OPTIONAL)
[ ] Install PM2: npm install -g pm2
[ ] Stop npm start (Ctrl+C)
[ ] Jalankan: npm run pm2
[ ] Check status: pm2 status
[ ] Verify: Status "online"
[ ] Setup auto-start: pm2 startup
[ ] Save config: pm2 save
[ ] Verify: pm2 list (harus ada mikhmon-wa-gateway)

================================================================================
POST-INSTALLATION CHECKLIST
================================================================================

FUNCTIONALITY TEST
[ ] Gateway status: Connected
[ ] Phone number: Muncul
[ ] Test message: Terkirim
[ ] Generate voucher: Terkirim via WhatsApp
[ ] Bot command "HARGA": Berfungsi
[ ] Bot command "HELP": Berfungsi
[ ] Admin panel: Bisa diakses
[ ] QR code: Bisa muncul ulang jika logout

MONITORING
[ ] Admin panel bisa diakses
[ ] Status real-time update
[ ] Logs bisa dilihat: pm2 logs mikhmon-wa-gateway
[ ] Database logs: wa_message_logs table ada data
[ ] File logs: mikhmon/logs/whatsapp_log.txt ada data

SECURITY
[ ] API key sudah diganti (bukan default)
[ ] API key sama di .env dan whatsapp_config.php
[ ] File .env tidak di-commit ke git
[ ] Folder auth_info sudah ada (session data)
[ ] Port 3000 tidak terbuka ke public (jika production)

BACKUP
[ ] Backup folder: whatsapp-gateway/auth_info/
[ ] Backup file: whatsapp-gateway/.env
[ ] Backup file: include/whatsapp_config.php
[ ] Backup database: wa_message_logs table

DOCUMENTATION
[ ] Baca: WHATSAPP_GATEWAY_INSTALLED.txt
[ ] Baca: WHATSAPP_SELFHOSTED_QUICKSTART.md
[ ] Simpan: WHATSAPP_SELFHOSTED_GUIDE.md (untuk referensi)
[ ] Bookmark: Admin panel URL

================================================================================
TROUBLESHOOTING CHECKLIST
================================================================================

JIKA QR CODE TIDAK MUNCUL:
[ ] Gateway sudah running? (pm2 status atau cek terminal)
[ ] Tunggu 10-30 detik
[ ] Refresh halaman admin panel
[ ] Restart gateway: pm2 restart mikhmon-wa-gateway
[ ] Check logs: pm2 logs mikhmon-wa-gateway
[ ] Check port: netstat -an | grep 3000 (Linux) atau netstat -an | findstr 3000 (Windows)

JIKA PESAN TIDAK TERKIRIM:
[ ] Status connected? (cek admin panel)
[ ] Gateway masih running? (pm2 status)
[ ] API key sama? (cek .env dan whatsapp_config.php)
[ ] Format nomor benar? (08xxx atau 62xxx)
[ ] Internet stabil?
[ ] Check logs: pm2 logs mikhmon-wa-gateway
[ ] Check database: SELECT * FROM wa_message_logs ORDER BY id DESC LIMIT 10;

JIKA GATEWAY CRASH:
[ ] Check logs: pm2 logs mikhmon-wa-gateway
[ ] Check error message
[ ] Restart: pm2 restart mikhmon-wa-gateway
[ ] Jika masih crash, reinstall: cd whatsapp-gateway && npm install
[ ] Check Node.js version: node --version (harus 16+)
[ ] Check disk space: df -h (Linux) atau dir (Windows)
[ ] Check RAM: free -m (Linux) atau Task Manager (Windows)

JIKA CONNECTION SERING PUTUS:
[ ] Internet stabil?
[ ] Gateway auto-reconnect? (tunggu 5-10 detik)
[ ] Scan QR code ulang jika perlu
[ ] PM2 auto-start enabled? (pm2 startup && pm2 save)
[ ] Check logs untuk error pattern
[ ] Restart router/modem jika perlu

JIKA PORT 3000 SUDAH DIPAKAI:
[ ] Edit .env: PORT=3001
[ ] Edit whatsapp_config.php: SELFHOSTED_API_URL dengan port 3001
[ ] Restart gateway
[ ] Test: curl http://localhost:3001/health

================================================================================
MAINTENANCE CHECKLIST (WEEKLY)
================================================================================

[ ] Check gateway status: pm2 status
[ ] Check connection: Admin panel
[ ] Check logs: pm2 logs mikhmon-wa-gateway
[ ] Check disk space: df -h atau dir
[ ] Check message logs: SELECT COUNT(*) FROM wa_message_logs;
[ ] Backup session data: whatsapp-gateway/auth_info/
[ ] Clear old logs jika perlu
[ ] Update dependencies: npm update (optional)

================================================================================
MAINTENANCE CHECKLIST (MONTHLY)
================================================================================

[ ] Backup session data: whatsapp-gateway/auth_info/
[ ] Backup database: wa_message_logs, wa_sessions
[ ] Backup configuration: .env, whatsapp_config.php
[ ] Check Node.js updates: node --version
[ ] Check npm updates: npm outdated
[ ] Update dependencies: npm update
[ ] Restart gateway: pm2 restart mikhmon-wa-gateway
[ ] Test functionality: Send test message
[ ] Review logs untuk error patterns
[ ] Clean old logs: pm2 flush mikhmon-wa-gateway

================================================================================
UPGRADE CHECKLIST (FUTURE)
================================================================================

WHEN NEW VERSION AVAILABLE:
[ ] Backup current installation
[ ] Backup session data (auth_info/)
[ ] Backup configuration (.env)
[ ] Read changelog/release notes
[ ] Stop gateway: pm2 stop mikhmon-wa-gateway
[ ] Pull new code: git pull (jika dari git)
[ ] Install new dependencies: npm install
[ ] Update configuration jika ada perubahan
[ ] Start gateway: pm2 start mikhmon-wa-gateway
[ ] Test functionality
[ ] Monitor logs untuk error

================================================================================
EMERGENCY CHECKLIST
================================================================================

JIKA GATEWAY TIDAK BISA START:
[ ] Check Node.js installed: node --version
[ ] Check dependencies: cd whatsapp-gateway && npm install
[ ] Check .env file exists
[ ] Check port available: netstat -an | grep 3000
[ ] Check logs: pm2 logs mikhmon-wa-gateway
[ ] Try manual start: npm start
[ ] Check error message
[ ] Reinstall jika perlu

JIKA SESSION HILANG:
[ ] Restore dari backup (auth_info/)
[ ] Jika tidak ada backup, scan QR code ulang
[ ] Logout dari WhatsApp Web di HP
[ ] Restart gateway
[ ] Scan QR code baru

JIKA DATABASE ERROR:
[ ] Check MySQL running: systemctl status mysql (Linux)
[ ] Check database exists: SHOW DATABASES;
[ ] Check table exists: SHOW TABLES;
[ ] Create table jika tidak ada (lihat src/database.js)
[ ] Check credentials di .env
[ ] Restart MySQL jika perlu

================================================================================
SUCCESS INDICATORS
================================================================================

✅ Gateway status: Connected
✅ Phone number: Muncul di admin panel
✅ Test message: Terkirim
✅ Generate voucher: Terkirim via WhatsApp
✅ Bot commands: Berfungsi
✅ Logs: Tidak ada error
✅ PM2 status: Online
✅ Auto-start: Enabled
✅ Backup: Done

================================================================================
FINAL CHECKLIST
================================================================================

[ ] ✅ Gateway installed
[ ] ✅ Gateway running
[ ] ✅ QR code scanned
[ ] ✅ Status connected
[ ] ✅ Test message sent
[ ] ✅ Voucher sent via WhatsApp
[ ] ✅ Bot commands working
[ ] ✅ PM2 configured
[ ] ✅ Auto-start enabled
[ ] ✅ Backup done
[ ] ✅ Documentation read
[ ] ✅ Admin panel bookmarked

================================================================================
CONGRATULATIONS! 🎉
================================================================================

Jika semua checklist di atas sudah ✅, maka instalasi Anda BERHASIL!

WhatsApp Gateway self-hosted sudah siap digunakan untuk:
- Kirim voucher otomatis via WhatsApp
- Bot WhatsApp untuk customer
- Unlimited messages
- Full control & privacy

Selamat menggunakan! 🚀

================================================================================
QUICK REFERENCE
================================================================================

Start Gateway:
  cd whatsapp-gateway && npm start

Production (PM2):
  npm run pm2
  pm2 status
  pm2 logs mikhmon-wa-gateway

Admin Panel:
  http://localhost/mikhmon/settings/whatsapp_gateway_admin.php

Health Check:
  http://localhost:3000/health

Logs:
  pm2 logs mikhmon-wa-gateway
  tail -f mikhmon/logs/whatsapp_log.txt

Restart:
  pm2 restart mikhmon-wa-gateway

Stop:
  pm2 stop mikhmon-wa-gateway

Documentation:
  WHATSAPP_GATEWAY_INSTALLED.txt
  WHATSAPP_SELFHOSTED_QUICKSTART.md
  WHATSAPP_SELFHOSTED_GUIDE.md

================================================================================

Version: 1.0.0
License: GPL-2.0
Author: MikhMon Team

================================================================================
